home *** CD-ROM | disk | FTP | other *** search
/ Aminet 8 / Aminet 8 (1995)(GTI - Schatztruhe)[!][Oct 1995].iso / Aminet / dev / gcc / gcc270_src.lha / gcc-2.7.0-amiga / config / i386 / sol2-c1.asm < prev    next >
Assembly Source File  |  1995-06-15  |  5KB  |  157 lines

  1. ! crt1.s for Solaris 2, x86
  2.  
  3. !   Copyright (C) 1993 Free Software Foundation, Inc.
  4. !   Written By Fred Fish, Nov 1992
  5. ! This file is free software; you can redistribute it and/or modify it
  6. ! under the terms of the GNU General Public License as published by the
  7. ! Free Software Foundation; either version 2, or (at your option) any
  8. ! later version.
  9. ! In addition to the permissions in the GNU General Public License, the
  10. ! Free Software Foundation gives you unlimited permission to link the
  11. ! compiled version of this file with other programs, and to distribute
  12. ! those programs without any restriction coming from the use of this
  13. ! file.  (The General Public License restrictions do apply in other
  14. ! respects; for example, they cover modification of the file, and
  15. ! distribution when not linked into another program.)
  16. ! This file is distributed in the hope that it will be useful, but
  17. ! WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  19. ! General Public License for more details.
  20. ! You should have received a copy of the GNU General Public License
  21. ! along with this program; see the file COPYING.  If not, write to
  22. ! the Free Software Foundation, 59 Temple Place - Suite 330,
  23. ! Boston, MA 02111-1307, USA.
  24. !    As a special exception, if you link this library with files
  25. !    compiled with GCC to produce an executable, this does not cause
  26. !    the resulting executable to be covered by the GNU General Public License.
  27. !    This exception does not however invalidate any other reasons why
  28. !    the executable file might be covered by the GNU General Public License.
  29.  
  30. ! This file takes control of the process from the kernel, as specified
  31. ! in section 3 of the System V Application Binary Interface, Intel386
  32. ! Processor Supplement.  It has been constructed from information obtained
  33. ! from the ABI, information obtained from single stepping existing
  34. ! Solaris executables through their startup code with gdb, and from
  35. ! information obtained by single stepping executables on other i386 SVR4
  36. ! implementations.  This file is the first thing linked into any executable.
  37.  
  38.     .file    "crt1.s"
  39.     .ident    "GNU C crt1.s"
  40.     .weak    _cleanup
  41.     .weak    _DYNAMIC
  42.     .text
  43.  
  44. ! Start creating the initial frame by pushing a NULL value for the return
  45. ! address of the initial frame, and mark the end of the stack frame chain
  46. ! (the innermost stack frame) with a NULL value, per page 3-32 of the ABI.
  47. ! Initialize the first stack frame pointer in %ebp (the contents of which
  48. ! are unspecified at process initialization).
  49.  
  50.     .globl    _start
  51. _start:
  52.     pushl    $0x0
  53.     pushl    $0x0
  54.     movl    %esp,%ebp
  55.  
  56. ! As specified per page 3-32 of the ABI, %edx contains a function 
  57. ! pointer that should be registered with atexit(), for proper
  58. ! shared object termination.  Just push it onto the stack for now
  59. ! to preserve it.  We want to register _cleanup() first.
  60.  
  61.     pushl    %edx
  62.  
  63. ! Check to see if there is an _cleanup() function linked in, and if
  64. ! so, register it with atexit() as the last thing to be run by
  65. ! atexit().
  66.  
  67.     movl    $_cleanup,%eax
  68.     testl    %eax,%eax
  69.     je    .L1
  70.     pushl    $_cleanup
  71.     call    atexit
  72.     addl    $0x4,%esp
  73. .L1:
  74.  
  75. ! Now check to see if we have an _DYNAMIC table, and if so then
  76. ! we need to register the function pointer previously in %edx, but
  77. ! now conveniently saved on the stack as the argument to pass to
  78. ! atexit().
  79.  
  80.     movl    $_DYNAMIC,%eax
  81.     testl    %eax,%eax
  82.     je    .L2
  83.     call    atexit
  84. .L2:
  85.  
  86. ! Register _fini() with atexit().  We will take care of calling _init()
  87. ! directly.
  88.  
  89.     pushl    $_fini
  90.     call    atexit
  91.  
  92. ! Compute the address of the environment vector on the stack and load
  93. ! it into the global variable _environ.  Currently argc is at 8 off
  94. ! the frame pointer.  Fetch the argument count into %eax, scale by the
  95. ! size of each arg (4 bytes) and compute the address of the environment
  96. ! vector which is 16 bytes (the two zero words we pushed, plus argc,
  97. ! plus the null word terminating the arg vector) further up the stack,
  98. ! off the frame pointer (whew!).
  99.  
  100.     movl    8(%ebp),%eax
  101.     leal    16(%ebp,%eax,4),%edx
  102.     movl    %edx,_environ
  103.  
  104. ! Push the environment vector pointer, the argument vector pointer,
  105. ! and the argument count on to the stack to set up the arguments
  106. ! for _init(), _fpstart(), and main().  Note that the environment
  107. ! vector pointer and the arg count were previously loaded into
  108. ! %edx and %eax respectively.  The only new value we need to compute
  109. ! is the argument vector pointer, which is at a fixed address off
  110. ! the initial frame pointer.
  111.  
  112.     pushl    %edx
  113.     leal    12(%ebp),%edx
  114.     pushl    %edx
  115.     pushl    %eax
  116.  
  117. ! Call _init(argc, argv, environ), _fpstart(argc, argv, environ), and
  118. ! main(argc, argv, environ).
  119.  
  120.     call    _init
  121.     call    __fpstart
  122.     call    main
  123.  
  124. ! Pop the argc, argv, and environ arguments off the stack, push the
  125. ! value returned from main(), and call exit().
  126.  
  127.     addl    $12,%esp
  128.     pushl    %eax
  129.     call    exit
  130.  
  131. ! An inline equivalent of _exit, as specified in Figure 3-26 of the ABI.
  132.  
  133.     pushl    $0x0
  134.     movl    $0x1,%eax
  135.     lcall    $7,$0
  136.  
  137. ! If all else fails, just try a halt!
  138.  
  139.     hlt
  140.     .type    _start,@function
  141.     .size    _start,.-_start
  142.  
  143. ! A dummy profiling support routine for non-profiling executables,
  144. ! in case we link in some objects that have been compiled for profiling.
  145.  
  146.     .globl    _mcount
  147. _mcount:
  148.     ret
  149.     .type    _mcount,@function
  150.     .size    _mcount,.-_mcount
  151.